import React, { Component } from 'react';
import { Layout, Menu } from 'antd';
import { Link, withRouter } from 'react-router-dom';
import style from './EvaluateSecondNav.less';

const getUrlParam = paraName => {
  let url = document.location.toString();
  let arrObj = url.split('?');
  if (arrObj.length > 1) {
    let arrPara = arrObj[1].split('&');
    let arr;
    for (let i = 0; i < arrPara.length; i++) {
      arr = arrPara[i].split('=');
      if (arr != null && arr[0] == paraName) {
        return arr[1];
      }
    }
    return '';
  }
  return '';
};

export default
@withRouter
class SecondNav extends Component {
  static displayName = 'SecondNav';

  static propTypes = {};

  static defaultProps = {};

  constructor(props) {
    super(props);
    // console.log("secondnav",props)
    this.state = {
      tabs: [],
      tabName: '',
      activeKey: '0',
      // activeKey: localStorage.getItem("subMenu") ? localStorage.getItem("subMenu") : "1",
    };
  }

  componentDidMount() {
    this.setActiveKey();
  }

  setActiveKey(paraName) {
    let url = document.location.toString();
    if (url.indexOf('/Evaluate/Compliance') != -1) {
      this.setState({
        activeKey: '0',
      });
    } else if (url.indexOf('/Evaluate/BusinessPerformance') != -1) {
      this.setState({
        activeKey: '1',
      });
    } else if (url.indexOf('/Evaluate/FinancialAnalysis') != -1) {
      this.setState({
        activeKey: '2',
      });
    } else if (url.indexOf('/Evaluate/MarketFluctuation') != -1) {
      this.setState({
        activeKey: '3',
      });
    } else {
      this.setState({
        activeKey: '0',
      });
    }
  }

  handleChange = e => {
    const key = e.key;
    localStorage.setItem('subMenu', key);
    this.setState({
      activeKey: key,
    });
    if (key === '0') {
      // 信披合规
      this.props.history.push(`/Evaluate/Compliance`);
    } else if (key === '1') {
      // 经营绩效
      this.props.history.push(`/Evaluate/BusinessPerformance`);
    } else if (key === '2') {
      // 财务分析
      this.props.history.push(`/Evaluate/FinancialAnalysis`);
    } else if (key == '3') {
      // 市场波动
      this.props.history.push(`/Evaluate/MarketFluctuation`);
      // window.location.href = `${global.constants.GOLDEYELOCALHOST}gdBeta2/#/evaluate/marketVolatility?secu_code=${this.getUrlParam("secu_code")}`
    } else if (key == '4') {
      // this.props.history.push(`/Evaluate/PublicOpinion?secu_code=${this.getUrlParam("secu_code")}`)
    }
  };

  render() {
    return (
      <div className={style.SecondMenu}>
        <Menu
          mode="horizontal"
          className="second-menu-main"
          // theme="light"
          // defaultSelectedKeys={["0"]}
          selectedKeys={[`${this.state.activeKey}`]}
          onSelect={this.handleChange.bind(this)}
        >
          <Menu.Item key="0">信披合规</Menu.Item>

          <Menu.Item key="1">经营绩效</Menu.Item>

          <Menu.Item key="2">财务分析</Menu.Item>

          <Menu.Item key="3">市场波动</Menu.Item>

          <Menu.Item key="4">舆情导向</Menu.Item>
        </Menu>
      </div>
    );
  }
}
